package chapter3_v4;

/**
 * @author mazouri
 * @create 2021-10-31 21:30
 */
public class _4 {
    public static void main(String[] args) {
        Point[] points = new Point[5];
        Point[] res = convexHull(points);
    }

    /**
     * 横（纵）坐标最小和最大的两个点一定为点集合凸包的两个极点。
     *
     * @param points 点集合
     * @return 点集合凸包的两个极点
     */
    public static Point[] convexHull(Point[] points) {
        int l = 0;
        int r = points.length - 1;

        for (int i = 0; i < points.length; i++) {
            //找出横坐标最大值和最小值
            if (points[i].x < points[l].x) l = i;
            if (points[i].x > points[r].x) r = i;
        }

        return new Point[]{points[l], points[r]};
    }

    private static class Point {
        private double x;
        private double y;

        public Point(double x, double y) {
            this.x = x;
            this.y = y;
        }
    }
}
